#!/bin/sh

### BEGIN INIT INFO
# Provides:       pull-hostname
# Required-Start: 
# Required-Stop:  
# Should-Start:   
# Should-Stop:    
# Default-Start:  S
# Default-Stop:   
# Description:    import hostname from boot partition if it exists
### END INIT INFO

prog=$(basename $0)
logger="logger -t $prog"

hostname_conf="/boot/coder_settings/hostname.txt"
hostname_dest_conf="/etc/hostname"
hosts_conf="/boot/coder_settings/hosts.txt"
hosts_dest_conf="/etc/hosts"


# copy from source to dest if source exists
if [ -f $hostname_conf ]; then
	echo "-----IMPORTING HOSTNAME FROM SD-----" | $logger
	cp $hostname_conf $hostname_dest_conf
	chown root:root $hostname_dest_conf
	chmod 644 $hostname_dest_conf

	HOSTNAME="$(cat /etc/hostname)"
	hostname "$HOSTNAME"
fi

# copy from source to dest if source exists
if [ -f $hosts_conf ]; then
	echo "-----IMPORTING HOSTS FROM SD-----" | $logger
	cp $hosts_conf $hosts_dest_conf
	chown root:root $hosts_dest_conf
	chmod 644 $hosts_dest_conf
fi



